﻿
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[proc_WebService_GetOrderDetails]
(
	@UserId varchar(20),
	@OrderId uniqueidentifier
)
AS
BEGIN
	Declare @n1 int,@n2 int

	Select @n1 = Count(0) From [Order]
	Where OId=@OrderId And (SalesmanAccount=@UserId	Or TrackKfAccount=@UserId 
	Or GenJinKfAccount=@UserId	Or TrackBDAccount=@UserId)

	Select @n2 = Count(0) From Project_Task
	Where OrderId=@OrderId And (DownPerson=@UserId Or ExecPerson=@UserId)

	If @n1=0 And @n2=0
		Set @OrderId='00000000-0000-0000-0000-000000000000'

	Select [CusName]
		  ,[CusPerson]
		  ,[CusPersonTel]
		  ,[OrderId]
		  ,[TypeName]
		  ,[WayName]
		  ,[Salesman]
		  ,[TradeDate]
		  ,[YingShouPrice]
		  ,[ShiShouPrice]
		  ,[TrackKfName]
		  ,[GenJinKfName]
--		  ,[AuditPerson]
		  ,[TrackBDName]
	From [Order]
	Where OId=@OrderId

	Select ProjectName,Title As TaskName,DownPersonName,ExecPersonName
	,IsNull((Select Top 1 ZhiWu From Employee e Where UserName=P.ExecPerson),'') As EPosition	--执行人的职务
	From Project_Task P
	Where OrderId=@OrderId And ExecPerson<>''
	Order By Id
END